package com.rapiddevsample;

import android.content.Intent;


import java.util.ArrayList;
import java.util.List;

import me.iwf.photopicker.PhotoPicker;
import me.iwf.photopicker.PhotoPreview;

import static android.app.Activity.RESULT_OK;

/**
 * ClassType:
 * User:wenyunzhao
 * ProjectName:RapidDevSample
 * Package_Name:com.rapiddevsample
 * Created on 2016-11-24 16:53
 */

public class Utils {

    /**
     * @param requestCode
     * @param resultCode
     * @param data
     * @param photoAdapter   适配器
     * @param selectedPhotos 适配器填充的集合
     */
    public static void setSelectorImgOnResult(int requestCode, int resultCode, Intent data, PhotoAdapter photoAdapter, ArrayList<String> selectedPhotos) {
        if (resultCode == RESULT_OK &&
                (requestCode == PhotoPicker.REQUEST_CODE
                        || requestCode == PhotoPreview.REQUEST_CODE)) {
            List<String> photos = null;
            if (data != null) {
                photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
                //                for (int i = 0; i < photos.size(); i++) {
                //                    bitmaps.add(compressImage(Uri.fromFile(new File(photos.get(i)))));
                //                    Log.d("压缩后：" + FFUtils.getBitmapFromPath(bitmaps.get(i)).getByteCount());
                //                }

            }
            selectedPhotos.clear();

            if (photos != null) {
                selectedPhotos.addAll(photos);
            }
            photoAdapter.notifyDataSetChanged();
        }
    }



}
